<?php 
class SpaceSettingModel extends Model{
	
	protected $tableName = "space";

	//保存设置
	function save_User_Setting($uid,$type,$data) {
		$setInfo = $this->where( 'uid='.$uid )->field( 'setting' )->find();
		$setInfo = unserialize( $setInfo['setting'] );
		
		if($type=='feed'){
			$template = require SITE_PATH.'/public/language/'.getLang().'/feeds.php';
		}else{
			$template = require SITE_PATH.'/public/language/'.getLang().'/notifys.php';
		}
		$template = array_keys($template);
		if(!$data) $data= array();
		$setInfo[$type] = array_diff($template,$data);
		return $this->setField('setting',serialize($setInfo),'uid='.$uid);
	}
	
	function get_User_Setting($uid,$type) {
		$default = array(   //默认排除的类型
			'notify' => array(),
			'email' => array('group_share_blog','share_ask','share_blog','comment_comment','wiki_comment','blog_comment','home_recordcomment','home_commentcomment','space_replaywall'),
			'feed'   => array(),
 		);
 		
		if($type=='feed'){
			$template = require SITE_PATH.'/public/language/'.getLang().'/feeds.php';
		}else{
			$template = require SITE_PATH.'/public/language/'.getLang().'/notifys.php';
		}
		$template = array_keys($template);
		$setInfo = $this->where( 'uid='.$uid )->field( 'setting' )->find();
		
		$setInfo = unserialize( $setInfo['setting'] );
		if(array_key_exists($type,$setInfo)){
			return array_diff( $template , $setInfo[$type] );
		}else{
			return array_diff( $template , $default[$type] );
		}
	}
}
?>